package cn.cxy.notepad.db.repository

import cn.cxy.notepad.db.AppDatabase
import cn.cxy.notepad.db.bean.Note
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext

class NoteRepository {
    private val noteDao = AppDatabase.getInstance().noteDao()
    suspend fun getNoteList(): List<Note> {
        return withContext(Dispatchers.IO) {
            noteDao.getNoteList()
        }
    }

    suspend fun add(name: String) {
        withContext(Dispatchers.IO) {
            val note = Note(0, name)
            noteDao.add(note)
        }
    }

    suspend fun update(note: Note) {
        withContext(Dispatchers.IO) {
            noteDao.update(note)
        }
    }
}